#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import os

from abc import ABC, abstractmethod
from ctools.common.ifilter import iFilter

from ctools.ly_parser.nodes import Node

from ctools.logext import *
import logging

_rlog, _plog, _mlog, _tlog = get_loggers(__file__, __name__, propagate=False)

class NConverterBase(ABC, object):

    def __init__(self, ifilter:iFilter=None):
        self._filter = ifilter

    def __repr__(self):
        return f"<{self.__class__.__name__}>"

    def set_filter(self, ifilter:iFilter):
        self._filter = ifilter

    def get_filter(self):
        return self._filter

    def _filter_item(self, itemname:str):
        if self._filter is None:
            return True
        return self._filter.filter_item(itemname)

class NConverterFilterBase(NConverterBase):

    def __init__(self, ifilter:iFilter=None):
        self._filter = ifilter

    def set_filter(self, ifilter:iFilter):
        self._filter = ifilter

    def get_filter(self):
        return self._filter

    def _filter_item(self, itemname:str):
        if self._filter is None:
            return True
        return self._filter.filter_item(itemname)
